package org.example.skytool.commom;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import org.example.dao.entity.post.PPost;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author 22449
 */
@Component
public class BeanUtils {


    public static void main(String[] args) {
        Map map = beanToMap(new PPost());
        Integer i = (Integer) map.get("likeNum");
        System.out.println(i);
        System.out.println(mapToBean(PPost.class,map));
    }

    public static Map<String, Object> beanToMap(Object obj){
        return BeanUtil.beanToMap(obj);
    }

    public static <T> T mapToBean(Class<T> clazz,Map map){
        return BeanUtil.mapToBean(map,clazz,false,new CopyOptions());
    }

}
